import re
import math
s="    -123csacacsasca"
s1="42"
s2="    -42"
s3="4139 with words"
s4="words and 987"
s5="-91283472332"
def myAtoi(s):
    re_rule=r"^\s*([+-]?[0-9]+)[^0-9]*"
    res=re.match(re_rule,s)
    if res:
        print(res.group(1))
        result=int(res.group(1))
        print(type(result))
        if result>math.pow(2,31)-1:
            return int(math.pow(2,31)-1)
        elif result<math.pow(-2,31):
            return int(math.pow(-2,31))
        return result
    else:
        return 0
print(myAtoi("42"))
